#ifndef MAIN_APPLICATION_H
#define MAIN_APPLICATION_H

//=============================================================================
//
// Controls:
// - A, D, W, S: Move Camera
// - X, Z: Zoom in, zoom out
//
//=============================================================================

#include "D3DConfiguration.h"

#include <D3dx10math.h>

#include "D3DFramework.h"
#include "Land.h"
#include "Light.h"
#include "Waves.h"

struct ID3D10Effect;
struct ID3D10EffectTechnique;
struct ID3D10InputLayout;
struct ID3D10EffectMatrixVariable;
struct ID3D10EffectVariable;
struct ID3D10EffectShaderResourceVariable;
struct ID3D10ShaderResourceView;
struct ID3D10BlendState;

namespace D3D10
{
	class MainApplication : public D3DFramework
	{
	public:
		MainApplication(const HINSTANCE hInstance);
		~MainApplication();
	
		void init();
		void onResize();
		void updateScene(const float deltaTime);
		void drawScene(); 
	
	private:
		void initEffect();
		void initInputLayout();
		void initBlendState();
		void initLights();

        void restoreDefaultStates();

		void updateViewMatrix(const float deltaTime);
		void updateWaves(const float deltaTime);
	
	private:	
		D3D10Utils::Land mLand;
		D3D10Utils::Waves mWaves;
	
		ID3D10Effect *mEffect;
		ID3D10EffectTechnique *mTechnique;
		ID3D10InputLayout *mInputLayout;

		ID3D10EffectMatrixVariable *mEffectWVPVariable;
		ID3D10EffectMatrixVariable *mEffectWorldVariable;
		ID3D10EffectMatrixVariable *mEffectTextureMatrixVariable;
		ID3D10EffectVariable *mEffectEyePositionVariable;
		ID3D10EffectVariable *mEffectLightVariable;
		ID3D10EffectShaderResourceVariable *mEffectDiffuseMapVariable;
		ID3D10EffectShaderResourceVariable *mEffectSpecularMapVariable;

		ID3D10ShaderResourceView *mGrassMapRV;
		ID3D10ShaderResourceView *mWaterMapRV;
		ID3D10ShaderResourceView *mSpecularMapRV;

		ID3D10BlendState *mBlendState;

		D3DXMATRIX mLandWorld;
		D3DXMATRIX mWavesWorld;

		D3DXMATRIX mView;
		D3DXMATRIX mProjection;
		D3DXMATRIX mWVP;

		D3DXVECTOR3 mEyePosition;

		D3DXVECTOR2 mWaterTextureOffset;

		D3D10Utils::Light mParallelLight;
			
		float mRadius;
		float mTheta;
		float mPhi;

		float mWavesTranslationOffset;
	};
}

#endif // MAIN_APPLICATION_H
